package com.djq.hhc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.djq.hhc.mapper.CreditInfoMapper;
import com.djq.hhc.model.credit.CreditInfo;
import com.djq.hhc.result.Result;
import com.djq.hhc.service.CreditInfoService;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: dadd7
 * @Date: 2023/03/05/下午 4:52
 * @Description:
 */

@Service
public class CreditInfoServiceImpl extends ServiceImpl<CreditInfoMapper, CreditInfo> implements CreditInfoService {
    @Override
    public Result getByUserId(Long id) {
        CreditInfo one = query().eq("user_id", id).one();
        if (one != null) {
            //存在，直接返回
            return Result.ok(one);
        } else {
            //不存在，创造一个加入数据库，然后返回
            CreditInfo creditInfo = new CreditInfo();
            creditInfo.setUserId(id);
            creditInfo.setCredit(100);
            save(creditInfo);
            return Result.ok(creditInfo);
        }
    }
}
